{extend name="base/common"}

{block name="style"}
<link rel="stylesheet" href="/static/datepicker/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" href="/static/iCheck/custom.css">
<link rel="stylesheet" href="/admin/css/chosen/chosen.css">
{/block}

{block name="page-header"}
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>通讯录</h2>
        <ol class="breadcrumb">
            <li>
                <a href="{:Url('Wechat/department')}">部门</a>
            </li>
            <li class="active">
                {eq name="type" value="0"}
                <strong>新增</strong>
                {else/}
                <strong>修改</strong>
                {/eq}
            </li>
        </ol>
    </div>
    <div class="col-lg-2">

    </div>
</div>
{/block}

{block name="main"}
<div class="wrapper wrapper-content animated fadeInRight ">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    {eq name="type" value="0"}
                    <h5>新增页面</h5>
                    {else/}
                    <h5>修改页面</h5>
                    {/eq}
                    <div class="ibox-tools">
                        <a href="javascript:window.history.go(-1);" class="btn btn-white btn-sm"><i class="fa fa-reply"></i> 返回</a>
                    </div>
                </div>
                <div class="ibox-content all">
                    <form id="form" class="form-horizontal" method="post" enctype="multipart/form-data">
                        <div class="form-group">
                            <div class="col-lg-1 text-right control-label">
                                <label>部门名称:</label>
                            </div>
                            <div class="col-lg-11">
                                <input type="text" placeholder="部门名称" class="form-control form_title" name="department" value="{$name|default=''}">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-lg-11 col-lg-offset-1">
                                <button class="btn btn-primary submit-btn post-add" type="button" target-form="form-horizontal">发布</button>
                                <a class="btn btn-default" href="javascript:window.history.go(-1);">返回</a>
                            </div>
                        </div>
                        <div class="selblo"></div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script src="/static/uploadify/jquery.uploadify.min.js"></script>
<script src="/static/iCheck/icheck.min.js"></script>
<script src="/static/ueditor/ueditor.config.js"></script>
<script src="/static/ueditor/ueditor.all.min.js"></script>
<script src="/admin/js/chosen.jquery.js"></script>
<script>
    //导航高亮
    highlight_subnav("{:Url('Wechat/department')}");
    //数据提交
    $('.post-add').click(function(){
        var name = $("input[name='department']").val().trim();
        var it = $(this);
        if(!name){
            warning({msg: "部门名称不能为空"});
        }
        $.ajax({
            type: 'post',
            url: "{:Url('Wechat/add_department')}",
            data: {
                'name' : name,
                'id' : "{$id}"
            },
            success: function(data){
                it.prop('disabled','true');
                it.next('button').prop('disabled','true');
                if(data.code == 1){
                    updateAlert(data.msg + ' 页面即将自动跳转~','success');
                    setTimeout(function(){
                        location.href = "{:Url('Wechat/department')}";
                        it.removeAttr('disabled');
                        it.next('button').removeAttr('disabled')
                    },2000);
                }else{
                    updateAlert(data.msg + '','error');
                    setTimeout(function(){
                        it.removeAttr('disabled');
                        it.next('button').removeAttr('disabled')
                    },1000);
                }
            }
        })
    })
</script>

{/block}